<template></template>
<script setup>
import { useRouter } from "vue-router";
import ajax from "../util/http";
const router = useRouter();

//获取被wx打乱后的url的query
const getQueryString = (name) => {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
};

let wxcode = getQueryString("code");
if (wxcode) {
  ajax.post("/star/wechat/oauth", { code: wxcode }).then((res) => {
    if (res.code == 1) {
      localStorage.setItem("open_id", res.data.open_id);
    }
  });

  router.replace({
    path: "/signin",
    query: {
      cid: getQueryString("cid"),
    },
  });
}
</script>